package project.menu.ordermenu;

import org.apache.log4j.Logger;
import project.controllers.Controller;
import project.controllers.Messager;
import project.controllers.Printer;
import project.menu.IMenu;
import project.menu.IMenuItem;
import project.work.Navigator;
import controllers.IAutoservice;
import entities.IOrder;

public class CopyOrder implements IMenuItem {

	private String name = "Copy order";
	private final Integer id = 6;
	private static IMenu submenu;
	private Controller controller;
	private Navigator navigator;
	private Logger log=Logger.getLogger(CopyOrder.class);

	public CopyOrder() {
		controller = Controller.getInstance();
		navigator = Navigator.getInstance();
	}

	public Integer getId() {
		return id;
	}

	public void action(IAutoservice autoservice) {

		IOrder clone = autoservice.cloneOrder(controller.getNumberOrder());
		if (clone != null) {
			Printer.printMessage(Messager.COPY_ORDER);
			autoservice.addOrder(clone, clone.getMaster().getNameMaster(), clone.getGarage()
					.getNumberGarage());
		} else {
			Printer.printMessage(Messager.WRONG_ORDER_NUMBER);
			log.error(Messager.WRONG_ORDER_NUMBER);
		}
		navigator.drawMenu(submenu);
	}

	public String getNameItem() {

		return name;
	}

	public static void setSubmenu(IMenu menu) {
		submenu = menu;
	}
}
